﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp.Infrastructure
{
    // 依赖环境 x86
    /*
     其他实现
    MSScriptControl.ScriptControl scc = new MSScriptControl.ScriptControl();
    scc.UseSafeSubset = true;
    scc.Language = "javascript";
    scc.AddCode(js);
    var rsapwd = scc.Run("test_enc", new object[] { encrypt, pwd });
     */

    /// <summary>
    /// js引擎
    /// </summary>
    public class JsEngineHelper
    {
        public void i(string msg)
        {
            Console.WriteLine(msg);
        }

        public void ExecuteJs(string js_path)
        {
            var script = File.ReadAllText(js_path, new UTF8Encoding(false));
            using (Noesis.Javascript.JavascriptContext context = new Noesis.Javascript.JavascriptContext())
            {
                context.SetParameter("_log", new JsEngineHelper());
                context.Run(script);
                // Getting a parameter
                // Console.WriteLine("number: " + context.GetParameter("number"));
            }
        }
    }
}
